const Koa = require("koa");
const path = require("path");
const views = require("koa-views");
const app = new Koa();

// 搭配koa
// 配置 EJS 视图引擎
app.use(views(path.join(__dirname, "views"), { extension: "ejs" }));

// 路由
app.use(async (ctx) => {
  await ctx.render("index", {
    title: "Hello Koa",
    name: "Tom",
    fruits: ["苹果", "香蕉", "橘子"],
  });
});

app.listen(3000, () => console.log("Server running on http://localhost:3000"));

// 不与koa使用

const ejs = require("ejs");

let data = {
  people: ["rost", "zks", "sada"],
};

let templateHtml = `
<ul>
<% for(let i=0;i<people.length;i++){ %>
    <li>    <%= people[i] %>    </li>
<% } %>
</ul>`;

// console.log(ejs.render(templateHtml, data));
